cc.Class({
    extends: cc.Component,

    properties: {

        id : '',
        loop  : true,
        music : true
    },
    
    onLoad()
    {
        let as = require('AudioSystem').share()

        as.play(this.id, this.loop, this.music,
            (aid, finish) =>{
                if (finish)
                {

                }
                else
                {
                    if (cc.isValid(this))
                    {
                        this.mSfx = aid
                        return true
                    }
                    
                    as.stop(aid)

                    return false
                }
            }
        )
    },

    onDestroy()
    {
        if (this.mSfx || this.mSfx === 0)
        {
            let as = require('AudioSystem').share()
            as.stop(this.mSfx)

            this.mSfx = null
        }
    }
});
